//
//  SEPrescriptionRecommendNewCell.swift
//  SmartEyeForDoctor
//
//  Created by TT on 2021/5/11.
//  Copyright © 2020 tao Tao. All rights reserved.
//

import UIKit

enum SEPrescriptionRecommendNewCellType: Int {
    case recommend, entrust
}

class SEPrescriptionRecommendNewCell: UITableViewCell, SETextViewDelegate {
    
    private var cellType: SEPrescriptionRecommendNewCellType = .recommend
    private var viewModel: SEPrescriptionViewModel?
    
    func update(with viewModel: SEPrescriptionViewModel, cellType: SEPrescriptionRecommendNewCellType) {
        self.viewModel = viewModel
        self.cellType = cellType
        textView.isEditable = viewModel.canEdit
        switch cellType {
        case .recommend:
            titleLabel.text = "医生意见"
            textView.text = viewModel.prescription.proposal
        case .entrust:
            titleLabel.text = "用药嘱托"
            textView.text = viewModel.prescription.remark
        }
    }
    
    @IBOutlet private weak var textBgView: UIView! {
        didSet {
            textBgView.backgroundColor = Asset.textviewBackground.color
            textBgView.layer.cornerRadius = 4
            textBgView.layer.masksToBounds = true
        }
    }
    
    @IBOutlet private weak var textView: SETextView! {
        didSet {
            textView.showTextCountView = false
            textView.text = ""
            textView.placeholder = "请输入内容"
            textView.tvDelegate = self
        }
    }
    
    @IBOutlet private weak var titleLabel: UILabel!
    
    func textViewDidEndEditing(_ textView: UITextView) {
        switch cellType {
        case .recommend:
            viewModel?.prescription.proposal = textView.text
        case .entrust:
            viewModel?.prescription.remark = textView.text
        }
    }
}
